from DrissionPage import Chromium, ChromiumOptions

import os
import datetime

today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)

def main():
    co = ChromiumOptions()#.headless()
    browser = Chromium(co)
    tab = browser.latest_tab
    tab.get('http://212.11.9.11:8077/static/#/login')
    userName = tab.ele('@name=username')
    userName.input('admin')
    password = tab.ele('@name=password')
    password.input('admin@123\n')
    tab.wait.load_start()

    tab.get('http://212.11.9.11:8077/static/#/report/realStatistics')
    tab.ele('自定义').click('js')
    tab.ele('t:input@@placeholder=开始时间').input(str(yesterday) + ' 00:00:00\n',
                                            clear=True)
    tab.ele('确定').click('js')
    tab.ele('t:input@@placeholder=结束时间').input(str(today) + ' 00:00:00\n',
                                            clear=True)
    tab.ele('确定').click('js')
    tab.wait(1)
    tab.ele(
        'x:/html/body/div/div/div[2]/div[2]/section/div[1]/div/div[1]/div/div[3]/div/input'
    ).input('温湿度\n\n', clear=True)
    tab('@title=通讯楼').click('js')
    tab('2层').click('js')
    select = tab('数据机房')
    select.click('js')
    select.parent(2).ele('t:label').click()
    [i.click('js') for i in tab.eles('温湿度')]
    tab.wait(1)
    mission = tab('下载').click.to_download('D:\lz\每日空调\liweibo',
                                        f'203温湿度{yesterday}',
                                        by_js=True)  # 点击一个会触发下载的链接，同时设置下载路径和文件名
    mission.wait()
    select.parent(2).ele('t:label').click()
    tab.wait(1)
    tab('3层',2).click('js')
    select = tab('303机房')
    select.click('js')
    select.parent(2).ele('t:label').click()
    [i.click('js') for i in tab.eles('温湿度')]
    tab.wait(1)
    mission = tab('下载').click.to_download('D:\lz\每日空调\liweibo',
                                        f'303温湿度{yesterday}',
                                        by_js=True)  # 点击一个会触发下载的链接，同时设置下载路径和文件名
    mission.wait()
    select.parent(2).ele('t:label').click()

    tab.get('http://212.11.9.11:8077/static/#/report/energyStatistics')
    tab.wait(1)
    tab.ele('t:input@@placeholder=开始时间').input(str(yesterday) + ' 00:00:00\n',clear=True)
    tab.ele('确定').click('js')
    tab.ele('t:input@@placeholder=结束时间').input(str(today) + ' 00:00:00\n',clear=True)
    tab.ele('确定').click('js')
    tab.wait(1)
    tab('203数据机房').parent(2).ele('t:label').click()
    tab('303数据机房').parent(2).ele('t:label').click()
    mission = tab('下载').click.to_download('D:\lz\每日空调\liweibo',
                                        f'203303能耗{yesterday}',
                                        by_js=True)  # 点击一个会触发下载的链接，同时设置下载路径和文件名
    mission.wait()
    browser.quit()
if __name__ == '__main__':
    main()
